package com.pmcc.miniProgram.vo;

import com.pmcc.utils.ApiResultBean;
import lombok.Data;

/**
 * @program: basePlatform
 * @description:
 * @author: Mr.Xue
 * @create: 2020-03-25 15:26
 **/
@Data
public class CodeExchangeOpenid {

    private String openid;//用户的唯一性标识
    private String session_key;//会话密钥session_key
    private String unionid;//如果开发者拥有多个移动应用、网站应用、和公众帐号（包括小程序），可通过unionid来区分用户的唯一性
    private String errcode;//返回的错误代码
    private String errmsg;//返回的错误信息

    private String access_token;//微信调用接口凭证
    private String expires_in;//access_token接口调用凭证超时时间，单位（秒）

    /**
     * 处理错误信息
     * @param codeExchangeOpenid
     * @param result
     */
    public static void handleError(CodeExchangeOpenid codeExchangeOpenid, ApiResultBean result){
        result.setCode(codeExchangeOpenid.getErrcode());
        if("40029".equals(codeExchangeOpenid.getErrcode())){
            result.setMsg("errcode:40029,"+"code 无效");
        }else if("45011".equals(codeExchangeOpenid.getErrcode())){
            result.setMsg("errcode:45011,"+"频率限制，每个用户每分钟100次");
        }else if("-1".equals(codeExchangeOpenid.getErrcode())){
            result.setMsg("errcode:-1,"+"系统繁忙，此时请开发者稍候再试");
        } else {
            result.setMsg(codeExchangeOpenid.getErrmsg());
        }
    }
}
